<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['visit:penalty:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['visit:penalty:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['visit:penalty:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['visit:penalty:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="penaltyList" @selection-change="handleSelectionChange">
      <!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="处罚ID" align="center" prop="apId"/>
      <el-table-column label="处罚单位" align="center" prop="apUnit"/>
      <el-table-column label="处罚事由" align="center" prop="apFor"/>
      <el-table-column label="处罚依据" align="center" prop="apBasis"/>
      <el-table-column label="处罚时间" align="center" prop="apTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.apTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处罚进程" align="center" prop="apProcess"/>
      <el-table-column label="处罚金额" align="center" prop="apAmount"/>
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['visit:penalty:edit']"
          >修改
          </el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.row)"
            v-hasPermi="['visit:penalty:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改行政处罚对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="60%">
      <el-form ref="form" :model="form" :rules="rules" class="clearfix  m-f-a-i" label-width="130px">
        <div class="content-left" style="width: 40%">
          <el-form-item label="处罚单位" prop="apUnit">
            <el-input v-model="form.apUnit" placeholder="请输入处罚单位"/>
          </el-form-item>
          <el-form-item label="处罚事由" prop="apFor">
            <el-input v-model="form.apFor" placeholder="请输入处罚事由"/>
          </el-form-item>
          <el-form-item label="处罚依据" prop="apBasis">
            <el-input v-model="form.apBasis" placeholder="请输入处罚依据"/>
          </el-form-item>
          <el-form-item label="处罚时间" prop="apTime">
            <el-date-picker clearable size="small"
                            v-model="form.apTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择处罚时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="处罚进程" prop="apProcess">
            <el-input v-model="form.apProcess" placeholder="请输入处罚进程"/>
          </el-form-item>
          <el-form-item label="处罚金额" prop="apAmount">
            <el-input v-model="form.apAmount" placeholder="请输入处罚金额"/>
          </el-form-item>
        </div>
        <div class="content-left" style="float: right; width: 45%">
          <el-form-item label="改正决定书">
            <fileUpload v-model="form.apOrderDecision"/>
          </el-form-item>
          <el-form-item label="改正决定书文号" prop="apOrderDecisionNum">
            <el-input v-model="form.apOrderDecisionNum" placeholder="请输入责令改正决定书文号"/>
          </el-form-item>
          <el-form-item label="事先告知">
            <fileUpload v-model="form.apBfNotice"/>
          </el-form-item>
          <el-form-item label="事先告知文号" prop="apBfNoticeNum">
            <el-input v-model="form.apBfNoticeNum" placeholder="请输入行政处罚事先"/>
          </el-form-item>
          <el-form-item label="告知书">
            <fileUpload v-model="form.apNotice"/>
          </el-form-item>
          <el-form-item label="告知书文号" prop="apNoticeNum">
            <el-input v-model="form.apNoticeNum" placeholder="请输入行政处罚告知书文号"/>
          </el-form-item>
          <el-form-item label="决定书">
            <fileUpload v-model="form.apDecision"/>
          </el-form-item>
          <el-form-item label="决定书文号" prop="apDecisionNum">
            <el-input v-model="form.apDecisionNum" placeholder="请输入行政处罚决定书文号"/>
          </el-form-item>
          <el-form-item label="缴费单" prop="apPaymentNote">
            <el-input v-model="form.apPaymentNote" placeholder="请输入行政处罚缴费单"/>
          </el-form-item>
          <el-form-item label="处决单位" prop="apExecutionUnit">
            <el-input v-model="form.apExecutionUnit" placeholder="请输入处决单位"/>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addPenalty, delPenalty, exportPenalty, getPenalty, listPenalty, updatePenalty} from "@/api/visit/penalty";

export default {
  name: "Penalty",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 行政处罚表格数据
      penaltyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询行政处罚列表 */
    getList() {
      this.loading = true;
      listPenalty(this.queryParams).then(response => {
        this.penaltyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        apId: null,
        apUnit: null,
        apFor: null,
        apBasis: null,
        apTime: null,
        apProcess: null,
        apAmount: null,
        apOrderDecision: null,
        apOrderDecisionNum: null,
        apBfNotice: null,
        apBfNoticeNum: null,
        apNotice: null,
        apNoticeNum: null,
        apDecision: null,
        apDecisionNum: null,
        apPaymentNote: null,
        apExecutionUnit: null,
        epId: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.apId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加行政处罚";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const apId = row.apId || this.ids
      getPenalty(apId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改行政处罚";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.apId != null) {
            updatePenalty(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPenalty(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const apIds = row.apId || this.ids;
      this.$confirm('是否确认删除行政处罚编号为"' + apIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delPenalty(apIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有行政处罚数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportPenalty(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>
